package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.tMesProQualityPojo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface tMesProQualityMapp {
    //查询数据表中有多少条数据
    @DS("newMscLowCodeFormal")
    @Select("SELECT COUNT(1) FROM T_MES_PRO_QUALITY")
    Integer queryAllCount();
    //查询200万数据，并返回
    @DS("newMscLowCodeFormal")
    @Select("SELECT * FROM T_MES_PRO_QUALITY ORDER BY F_BEGIN_TIME ASC LIMIT #{part} ")
    List<tMesProQualityPojo> queryPart(int part);

    //新建一个表，用于数据库分表
    @DS("newMscLowCodeFormal")
    @Update({
            "<script>",
            "CREATE TABLE IF NOT EXISTS `${tableName}` (",
            "  `ID` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',",
            "  `F_STATION_ID` VARCHAR(100) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '工位ID',",
            "  `F_RECORD_ID` VARCHAR(100) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '记录ID',",
            "  `F_MEASURE_ID` VARCHAR(200) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '测量项ID',",
            "  `F_VALUE` DECIMAL(18,4) DEFAULT NULL COMMENT '测量值',",
            "  `F_BEGIN_TIME` DATETIME(4) NOT NULL COMMENT '记录时间',",
            "  `MODEL_ID` VARCHAR(100) DEFAULT NULL COMMENT '机型ID',",
            "  `UP_VALUE` VARCHAR(100) DEFAULT NULL COMMENT '上限值',",
            "  `LOW_VALUE` VARCHAR(100) DEFAULT NULL COMMENT '下限值',",
            "  `EXCEPT_VALUE` VARCHAR(100) DEFAULT NULL COMMENT '异常值',",
            "  PRIMARY KEY (`ID`),",
            "  KEY `idx_station_time` (`F_STATION_ID`, `F_BEGIN_TIME`) COMMENT '工位时间索引'",
            ") ENGINE=InnoDB ",
            "AUTO_INCREMENT=11683146 ",
            "DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ",
            "COMMENT='MES生产质量数据表'",
            "</script>"
    })
    void newTable(@Param("tableName") String tableName);

    //将查询到的数据放入新建的分表中,实现功能在resources -> example.mapper->tMesProQualityMapp 中
    @DS("newMscLowCodeFormal")
    void insertCurrentData(List<tMesProQualityPojo> pojoList,String tableName);

    //查询到的数据放入分表中后，将这些数据从旧的表中删除，实现功能在resources -> example.mapper->tMesProQualityMapp 中
    @DS("newMscLowCodeFormal")
    void deleteCurrentData(List<tMesProQualityPojo> pojoList);
}
